package com.qf.fmall2202.utils;

import cn.hutool.jwt.JWT;
import com.qf.fmall2202.user.entity.Users;

/**
 * @Author: 可乐
 * @Description:
 * @CreateTime: 2022-11-03  16:31
 */
public class TokenUtils {
	public static String getToken( Users users){
		// 密钥
		byte[] key = "1234567890".getBytes();

		String token = JWT.create()
				.setPayload("username", users.getUsername())
				.setPayload("password", users.getPassword())
				.setKey(key)
				.sign();
		return token;
	}

	//验证token
	public static boolean doVerify(String token){
		// 密钥
		byte[] key = "1234567890".getBytes();

// 默认验证HS265的算法
		if(JWT.of( token ).setKey( key ).verify( )) {
			return true;

		}else {
			return false;
		}

	}
}
